package com.dianqiu.common.service.impl;

import java.util.List;


import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.dianqiu.base.service.impl.BaseService;
import com.dianqiu.common.bean.DqClubsTO;
import com.dianqiu.common.bean.DqLeagueClubsTO;
import com.dianqiu.common.bean.DqLeaguesTO;
import com.dianqiu.common.bean.DqMatchHistTO;
import com.dianqiu.common.bean.DqMatchTO;
import com.dianqiu.common.service.CreateMatchService;


@Component("createMatchService")
public class CreateMatchServiceImpl extends BaseService implements CreateMatchService {

	public List<DqLeaguesTO> getAllLeagues() {
		return this.getDqLeaguesDao().getAllLeagues();
	}
	
	public void save(DqMatchTO match){
		this.getDqMatchDao().save(match);
	}

	public List<DqClubsTO> getClubesById(Integer id) {
		return this.getDqClubsDao().getClubesById(id);
	}

	public List<DqLeaguesTO> getLeaguesById(Integer id) {
		return this.getDqLeaguesDao().getLeaguesById(id);
	}

	public List<DqLeagueClubsTO> getClubesByLeagueId(Integer leagueId) {
		return this.getDqLeagueClubsDao().getClubesByLeague(leagueId);
	}

	public String bindClubsByLeagueId(String leagueIdStr) {
		StringBuilder xmlCompanyTypeList = new StringBuilder();
		xmlCompanyTypeList
				.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
		xmlCompanyTypeList.append("<Root>\r\n");
		
		if(leagueIdStr != null && leagueIdStr != ""){
			Integer leagueId = Integer.valueOf(leagueIdStr);
			List<DqLeagueClubsTO> leagueClubsIdList = this.getClubesByLeagueId(leagueId);
			if (leagueClubsIdList != null) {
				for (int i = 0; i < leagueClubsIdList.size(); i++) {
					DqLeagueClubsTO leagueClubs =  leagueClubsIdList.get(i);
					xmlCompanyTypeList.append("<List>\r\n");
					xmlCompanyTypeList.append("<TextField>" + leagueClubs.getDqClubs().getClbEn().toString()
							+ "</TextField>\r\n");
					xmlCompanyTypeList.append("<ValueField>" + leagueClubs.getDqClubs().getClbId().toString()
							+ "</ValueField>\r\n");
					xmlCompanyTypeList.append("</List>\r\n");
				}
			}
		}
		xmlCompanyTypeList.append("</Root>");
		return xmlCompanyTypeList.toString();
	}

	@Override
	public void save(DqMatchHistTO matchHist) {
		// TODO Auto-generated method stub
		this.getDqMatchHistDao().save(matchHist);
	}
	
}